#include "myRect.h"
//����������� � ����������� ��� ������������� ���������� ������
Rect::Rect(int left, int right, int top, int bottom)
{	
	m_left = left;
	m_right = right;
	m_top = top;
	m_bottom = bottom;

	Standarting();
}
//����� "������������" ��������������
void Rect::Standarting()
{		
	if (m_right < m_left)
	{
		int tmp = m_right;
		m_right = m_left;
		m_left = tmp;
	}
	
	if (m_bottom < m_top)
	{
		int tmp = m_bottom;
		m_bottom = m_top;
		m_top = tmp;
	}		
}
//����� ������� ����������� ������� �������������� �� �������� ����������
void Rect::InflateRect(int left, int right, int top, int bottom)
{
	m_left -= left;
	m_right += right;
	m_top -= top;
	m_bottom += bottom;

	Standarting();	
}
//����� ������� ��������� ��� ���������, �� ��������� ������ 1
void Rect::InflateRect(int left, int right)
{
	m_left -= left;
	m_right += right;
	Standarting();
}
//����������� �����������
Rect::Rect(const Rect& other)
{
	m_left = other.m_left;
	m_right = other.m_right;
	m_top = other.m_top;
	m_bottom = other.m_bottom;
}
//����� ������� ����������� ���������� ������ ������������ ��������
void Rect::SetAll(int left, int right, int top, int bottom) 
{
	m_left = left;
	m_right = right;
	m_top = top;
	m_bottom = bottom;

	Standarting();
}

//����� ������� "�������" �������� private-���������� ������.
void Rect::GetAll(int& left, int& right, int& top, int& bottom) const
{
	left = m_left;
	right = m_right;
	top = m_top;
	bottom = m_bottom;
}

//��������� ��� ������� ������ Rect �� �������� � ���������� ������ ������ Rect, ������� �������� ���������������,
//� ������� ������� �������� ��������������.
Rect BoundingRect(Rect one, Rect two)
{
	Rect tmp;
	int one_left, one_right, one_top, one_bottom;
	int two_left, two_right, two_top, two_bottom;
	int tmp_left=0, tmp_right=0, tmp_top = 0, tmp_bottom = 0;

	one.GetAll(one_left, one_right, one_top, one_bottom);
	two.GetAll(two_left, two_right, two_top, two_bottom);

	(one_left <= two_left)? tmp_left = one_left : tmp_left = two_left;//��������� ��������

	(one_right >= two_right)? tmp_right = one_right : tmp_right = two_right;

	(one_top <= two_top)? tmp_top = one_top : tmp_top = two_top;
	
	(one_bottom >= two_bottom)?	tmp_bottom = one_bottom : tmp_bottom = two_bottom;
	
	tmp.SetAll(tmp_left, tmp_right, tmp_top, tmp_bottom);
	return tmp;
}

Rect BoundingRect2(const Rect& one, const Rect& two)
{
	Rect tmp;
	int one_left, one_right, one_top, one_bottom;
	int two_left, two_right, two_top, two_bottom;
	int tmp_left = 0, tmp_right = 0, tmp_top = 0, tmp_bottom = 0;

	one.GetAll(one_left, one_right, one_top, one_bottom);
	two.GetAll(two_left, two_right, two_top, two_bottom);

	if (one_left <= two_left)
	{
		tmp_left = one_left;
	}
	else { tmp_left = two_left; }//���� ������ ������? - ��������� ��������

	if (one_right >= two_right)
	{
		tmp_right = one_right;
	}
	else { tmp_right = two_right; }

	if (one_top <= two_top)
	{
		tmp_top = one_top;
	}
	else { tmp_top = two_top; }

	if (one_bottom >= two_bottom)
	{
		tmp_bottom = one_bottom;
	}
	else { tmp_bottom = two_bottom; }

	tmp.SetAll(tmp_left, tmp_right, tmp_top, tmp_bottom);
	return tmp;
}

Rect Rect::BoundingRect(const Rect& two)
{
	Rect tmp;

	(m_left <= two.m_left) ? tmp.m_left = m_left : tmp.m_left = two.m_left;//��������� ��������

	(m_right >= two.m_right) ? tmp.m_right = m_right : tmp.m_right = two.m_right;

	(m_top <= two.m_top) ? tmp.m_top = m_top : tmp.m_top = two.m_top;

	(m_bottom >= two.m_bottom) ? tmp.m_bottom = m_bottom : tmp.m_bottom = two.m_bottom;

	return tmp;
}

